home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / filesyst / thsfs.tgz / thsfs.tar / thsfs / file.c < prev    next >
C/C++ Source or Header  |  1994-10-04  |  2KB  |  102 lines

  1. /*************************************************************
  2.  *                                                           *
  3.  *    ths  Filesystem                  04.10.94      V1.1    *
  4.  *                                                           *
  5.  *    Thomas Scheuermann     ths@ai-lab.fh-furtwangen.de     *
  6.  *                                                           *
  7.  *************************************************************/
  8.  
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/sched.h>
  12. #include <linux/errno.h>
  13. #include <linux/string.h>
  14. #include <linux/stat.h>
  15. #include <linux/mm.h>
  16. #include <linux/locks.h>
  17. #include <linux/fs.h>
  18. #include <linux/malloc.h>
  19.  
  20. #include <asm/system.h>
  21. #include <asm/segment.h>
  22. #include <asm/bitops.h>
  23.  
  24. #include "ths.h"
  25. #include "ths_i.h"
  26.  
  27. int ths_read(struct inode *in, struct file *fp, char *buffer, int len)
  28. {
  29.     int i,diff;
  30.     long pos;
  31.     struct ths_buffer tbf;
  32.     struct ths_inode_info *ths_inode;
  33.     struct ths_sb_info *ths_sb;
  34.     unsigned char *data;
  35.  
  36. #ifdef DEBUG
  37.     printk("ths_read : %d Bytes\n",len);
  38. #endif
  39.  
  40.     ths_inode = (struct ths_inode_info *)&(in->u.generic_ip);
  41.     ths_sb = (struct ths_sb_info *)in->i_sb->u.generic_sbp;
  42.  
  43.     pos = fp->f_pos;
  44.     if(pos>=in->i_size)
  45.         return 0;
  46.  
  47.     if(ths_read_cluster(in->i_sb,ths_inode->Cluster,pos,&tbf))
  48.     {
  49.         printk("Fehler\n");
  50.         return -1;
  51.     }
  52.     data = tbf.data[(pos/512)%tbf.sektore];
  53.  
  54.     i = 0;
  55.  
  56.     diff = 512-(pos%512);
  57.     if(diff>len)
  58.         diff=len;
  59.     if((pos+diff)>in->i_size)
  60.         diff=in->i_size-pos;
  61.     memcpy_tofs(&buffer[i],&data[pos%512],diff);
  62.     i+=diff;
  63.     pos+=diff;
  64.  
  65.     if(!((pos/512)%tbf.sektore))
  66.         ths_free_cluster(&tbf);
  67.  
  68.     for(;i<len && pos<in->i_size;)
  69.     {
  70.         if(!(pos&0x1ff))
  71.         {
  72.             if(!((pos/512)%ths_sb->SektorenProCluster))
  73.             {
  74.                 if(ths_read_cluster(in->i_sb,ths_inode->Cluster,pos,&tbf))
  75.                 {
  76.                     printk("Fehler\n");
  77.                     return -1;
  78.                 }
  79.             }
  80.             data = tbf.data[(pos/512)%tbf.sektore];
  81.         }
  82.         diff=512;
  83.         if(i+diff>len)
  84.             diff=len-i;
  85.         if((pos+diff)>in->i_size)
  86.             diff=in->i_size-pos;
  87.         memcpy_tofs(&buffer[i],&data[pos%512],diff);
  88.         i+=diff;
  89.         pos+=diff;
  90.  
  91.         if(!((pos/512)%tbf.sektore))
  92.             ths_free_cluster(&tbf);
  93.     }
  94.     if((pos/512)%ths_sb->SektorenProCluster)
  95.         ths_free_cluster(&tbf);
  96.     fp->f_pos = pos;
  97.     return i;
  98. }
  99.  
  100.  
  101.  
  102.